<?php
namespace Todo\Model;

/**
 * 树型模板，继承自内存模型,主要是判断树形上下级关系
 * User: yepanpan
 * Date: 2016/8/8
 * Time: 17:59
 */
class TreeModel extends MemoryModel
{
    protected $order = 'pid ASC, sort ASC';

    /**
     * @param $data
     * @param $options
     * @return bool
     */
    protected function _before_update($data,$options){
        if(!$data['pid'] || !$data['id']) return true;
        if($data['pid'] == $data['id']) return false;
        //--------------判断三级------------------------------
        $pid =$this->keyFind($data['pid'], 'pid');
        if($pid == $data['id']) return false;
        $pid =$this->keyFind($data['pid'], 'pid');
        if($this->keyFind($pid, 'pid') == $data['id']) return false;
        $pid =$this->keyFind($data['pid'], 'pid');
        if($this->keyFind($pid, 'pid') == $data['id']) return false;
        return true;
    }
}